package swingxrcp.framework.client;

import java.io.IOException;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Properties;
import java.util.SimpleTimeZone;

import swingxrcp.framework.client.context.SwingXContext;
import swingxrcp.framework.model.domain.Config;
import swingxrcp.framework.model.environment.ClientSource;
import swingxrcp.framework.model.environment.Environment;
import swingxrcp.framework.model.environment.ServerSource;
import swingxrcp.framework.model.environment.UserContext;
import swingxrcp.framework.server.environment.Application;
import swingxrcp.framework.server.environment.Module;
import swingxrcp.framework.util.PropertiesUtils;

/**
 * 客户端环境信息
 *
 * @author liangfei
 *
 */
public class Client {
	private static Client client = new Client();
	private Client() {}

	public static Environment getEnvironment() {
		Application application = client.getApplication();
		Module module = client.getModule();
		UserContext userContext = client.getUserContext();
		ServerSource serverSource = client.getServerSource();
		ClientSource clientSource = client.getClientSource();
		return new Environment(application, module, userContext, serverSource, clientSource);
	}

	public Application getApplication() {
		Map<String, Properties> modulesProperties = new HashMap<String, Properties>();
		return new Application(new Properties(), modulesProperties);
	}

	public Module getModule() {
		return new Module("", new Properties(), false);
	}

	public UserContext getUserContext() {
		return new UserContext(new Object());
	}

	public ServerSource getServerSource() {
		return new ServerSource(new Locale("","",""), new SimpleTimeZone(3, ""), "");
	}

	public ClientSource getClientSource() {
		Config config = null;
		try {
			Properties properties = PropertiesUtils.loadFromFileSystem(SwingXContext.SWINGX_CONFIG_FILE);
			config = new Config(properties);
		} catch (IOException e) {
		}
		return new ClientSource(config, new Locale("","",""), new SimpleTimeZone(3, ""), "");
	}
}
